<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    //左右指针 找到中间数 平方后大 r-1 小l-1
    function fn(x) {
        let l = 0;
        let r = x;

        while (l < r) {
            let mid = Math.floor((r - l) / 2)
            if (mid * mid === x) {
                return mid
            } else if (mid < x) {
                l++
            } else {
                r++
            }
        }
        return -1

    }
    console.log(fn(81), "----¸");

</script>

</html>